﻿using OrderSystem.Common;
using OrderSystem.DataAccess;
using OrderSystem.Templet;
using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace OrderSystem
{
    public partial class FormAddShatter : FormTemplet
    {
        public FormAddShatter()
        {
            this.InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.txtRemark.Text.Trim().Length > 64)
            {
                MessageBox.Show("备注字符太长", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtRemark.Focus();
            }
            else
            {
                Shatters shatters = new Shatters();
                string text = null;
                try
                {
                    text = shatters.InsertShatter("", this.txtRemark.Text.Trim(), LoginInfo.OperatorID);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                shatters.Dispose();
                if (text != null)
                {
                    MessageBox.Show("补片单创建成功", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    new FormShatterInfo(text)
                    {
                        MdiParent = base.MdiParent
                    }.Show();
                    base.Close();
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }
    }
}
